
var gulp = require('gulp');
var rename = require('gulp-rename');
var runSequence = require('gulp-sequence');
var judgeCef = require('judge-cef');
var es6 = require('es6-cef');


/**
 * 需要拷贝的路径，自己手动配置
 * basePath：配置JS根目录
 * enterFile：配置页面的根html
 * 温馨提示：建议basePaht只传一个目录，enterFile也是只传一个html，多个的情况还存在问题
 * @type {Array}
 */
var basePath = ['TESTPLAN/subscribe/js'];
var enterFile = ['TESTPLAN/subscribe/index.html'];
// var basePath = ['demo'];
// var enterFile = ['demo/testClientApi.html'];

/**
 * 拷贝文件
 * @return {[type]} [description]
 */
gulp.task("copyDir",function(){
    return gulp.src(basePath[0]+'/**/*.*')
        .pipe(gulp.dest('./'+basePath[0]+'-cef/'));
});

gulp.task("createPKjs", function () {
    return  gulp.src(enterFile)
            .pipe(judgeCef.getScriptContent(basePath))
            .pipe(rename("judgeCef.js"))
            .pipe(gulp.dest("./"));
});

gulp.task("modifyEnterFile", function () {
    return gulp.src(enterFile)
        .pipe(judgeCef.commentScript())
        .pipe(gulp.dest("./"));
});


gulp.task('findFunction',function(){
  return gulp.src( basePath[0]+'-cef/**/*.*')
       .pipe(es6.es6(0))
       .pipe(gulp.dest( basePath[0]+'-cef'));
});


gulp.task('addAsync', function() {
    return gulp.src( basePath[0]+'-cef/**/*.*')
     .pipe(es6.es6(1))
     .pipe(gulp.dest( basePath[0]+'-cef'));
});


gulp.task('default', function(cb) {
    runSequence('copyDir', 'createPKjs', 'modifyEnterFile','findFunction','addAsync')(cb);
});


gulp.task('cef', function(cb) {
    runSequence('findFunction','addAsync')(cb);
});

